home *** CD-ROM | disk | FTP | other *** search
/ Wild Blue Yonder 1: 50 Years of Gs & Jets / Wild Blue Yonder - Episode 1 - 50 Years of Gs and Jets (Digital Ranch) (Spectrum Holobyte)(1-107-40-101)(1994).iso / control / panel.dir / 00749_Script_749 < prev    next >
Text File  |  1994-08-29  |  6KB  |  303 lines

  1. ----------------------------------------------------------------------------------------
  2. -- Handlers in this section control the ambient sound.
  3. ----------------------------------------------------------------------------------------
  4.  
  5. on initAmbience
  6.   global ambienceCode
  7.   
  8.   if ambienceCode <> 1 then
  9.     set ambienceCode = 1
  10.     countSounds 
  11.     startAmbience   
  12.   end if
  13.   
  14. end initAmbience
  15.  
  16.  
  17.  
  18.  
  19. on startAmbience
  20.   chooseChannels  
  21.   crossFade
  22. end startAmbience
  23.  
  24.  
  25.  
  26.  
  27. -- countSounds examines the ambience array to find out how many ambient
  28. -- sounds are associated with the movie.  It stores the total in a 
  29. -- variable called overviewSounds.
  30.  
  31. on countSounds
  32.   
  33.   global overviewSounds, ambience, ambienceCode
  34.   
  35.   set overviewSounds = 0
  36.   set contents = 1
  37.   set pointer = ambienceCode
  38.   
  39.   repeat while pointer < (ambienceCode + 99)
  40.     set contents = ambience( mGet, pointer )
  41.     if contents = 0 then 
  42.       exit repeat
  43.     end if
  44.     set pointer = pointer + 1
  45.     set overviewSounds = overviewSounds + 1
  46.   end repeat
  47.   
  48. end countSounds
  49.  
  50.  
  51.  
  52.  
  53.  
  54. on chooseChannels
  55.   global fadeInLength, inChannel, outChannel
  56.   
  57.   if (the volume of sound 1 > the volume of sound 2) or ¼
  58.     ((the volume of sound 1 < the volume of sound 2) and ¼
  59.      (playTime() < fadeInLength/2)) then
  60.     set inChannel  = 1
  61.     set outChannel = 2
  62.   else 
  63.     set inChannel  = 2
  64.     set outChannel = 1
  65.   end if
  66.   
  67. end chooseChannels
  68.  
  69.  
  70.  
  71.  
  72.  
  73. -- crossFade chooses a new cut to play, then fades it in while fading
  74. -- out the old one.
  75.  
  76. on crossFade
  77.   global inChannel, outChannel, fadeOutLength, fadeInLength 
  78.   
  79.   set temp = inChannel
  80.   set inChannel = outChannel
  81.   set outChannel = temp
  82.   
  83.   chooseCut
  84.   
  85.   initFadeOut( outChannel )
  86.   fadeOut( outChannel, fadeOutLength )
  87.   initFadeIn( inChannel )
  88.   fadeIn( inChannel, fadeInLength )
  89.   playCut
  90. end crossFade
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. on checkAmbience
  98.   global fadedIn, fadedOut, inChannel, outChannel, fadeInLength, ¼
  99.          fadeOutLength
  100.   
  101.   if not soundBusy( inChannel ) and not soundBusy( outChannel ) then ¼
  102.     startAmbience
  103.   if not fadedIn then fadeIn( inChannel, fadeInLength )
  104.   if not fadedOut then fadeOut( outChannel, fadeOutLength )
  105.   if nearEnd() then crossFade
  106. end checkAmbience
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. -- chooseCut randomly selects the number of the next cut to play.  If possible, it
  114. -- never repeats the same cut twice in a row.
  115.  
  116. on chooseCut
  117.   
  118.   global cut, overviewSounds, oldOverviewSound
  119.   
  120.   set i = random( overviewSounds )
  121.   set cut = 1 + (i - 1)
  122.   
  123.   if overviewSounds > 1 then             -- If there are two or more choices, don't repeat.
  124.     if cut = oldOverviewSound then 
  125.       chooseCut
  126.     else
  127.       set oldOverviewSound = cut
  128.     end if
  129.   end if
  130.   
  131. end chooseCut  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. -- nearEnd checks to see whether the current audio selection has reached
  138. -- the point at which it should start fading out.  (Values were assigned
  139. -- to the array called "fadePoint" in the Overview movie.)
  140.  
  141. on nearEnd
  142.   global cut, fadePoint
  143.   
  144.   if playTime() < fadePoint( mGet, cut ) then
  145.     return FALSE
  146.   else
  147.     return TRUE
  148.   end if
  149.   
  150. end nearEnd
  151.  
  152.  
  153.  
  154.  
  155. on initFadeOut channel
  156.   global bgVol, lastTimeOut, startVol, fracSumOut, fadedOut, volumes
  157.   set lastTimeOut   = the timer
  158.   set startVol      = volumes( mGet, bgVol )
  159.   set fracSumOut    = 0
  160.   set fadedOut      = FALSE
  161. end initFadeOut
  162.  
  163.  
  164.  
  165.  
  166.  
  167. on fadeOut channel, length
  168.   
  169.   global lastTimeOut, startVol, fracSumOut, fadedOut
  170.   
  171.   if the timer > lastTimeOut then
  172.     set elapsedTime = (the timer - lastTimeOut) * 1.0000000
  173.     set lastTimeOut = the timer
  174.     set increment = (elapsedTime/length) * startVol
  175.     set increment = storeFractionOut( increment )
  176.     
  177.     if fracSumOut >= 1 then
  178.       set increment  = increment + 1
  179.       set fracSumOut = fracSumOut - 1
  180.     end if
  181.     
  182.     set the volume of sound channel = (the volume of sound channel) - increment
  183.     
  184.     if (the volume of sound channel) = 0 then
  185.       sound stop channel
  186.       set fadedOut = TRUE
  187.     end if
  188.     
  189.   end if
  190.   
  191. end fadeOut
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. on initFadeIn channel
  199.   global lastTimeIn, maxVol, volumes, bgVol, fracSumIn, fadedIn
  200.   set the volume of sound channel = 0  
  201.   set lastTimeIn                  = the timer
  202.   set maxVol                      = volumes( mGet, bgVol )
  203.   set fracSumIn                   = 0
  204.   set fadedIn                     = FALSE
  205. end initFadeIn
  206.  
  207.  
  208.  
  209.  
  210. on fadeIn channel, length
  211.   
  212.   global lastTimeIn, maxVol, fracSumIn, fadedIn, volumes, bgVol
  213.   
  214.   if the timer > lastTimeIn then
  215.     set elapsedTime = (the timer - lastTimeIn) * 1.0000000
  216.     set lastTimeIn = the timer
  217.     set increment = (elapsedTime/length) * maxVol
  218.     set increment = storeFractionIn( increment )
  219.     
  220.     if fracSumIn >= 1 then
  221.       set increment = increment + 1
  222.       set fracSumIn = fracSumIn - 1
  223.     end if
  224.     
  225.     if ((the volume of sound channel) + increment) < maxVol then
  226.       set the volume of sound channel = (the volume of sound channel) + increment
  227.     else
  228.       set the volume of sound channel = maxVol
  229.       set fadedIn = TRUE
  230.     end if
  231.     
  232.   end if
  233.   
  234. end fadeIn
  235.  
  236.  
  237.  
  238.  
  239. on storeFractionOut n
  240.   global fracSumOut
  241.   set int  = integer( n )
  242.   set frac = n - int
  243.   
  244.   if frac < 0 then
  245.     set frac = frac + 1
  246.     set int = int - 1
  247.   end if
  248.   
  249.   set fracSumOut = fracSumOut + frac
  250.   return int
  251. end storeFractionOut
  252.  
  253.  
  254.  
  255.  
  256. on storeFractionIn n
  257.   global fracSumIn
  258.   set int  = integer( n )
  259.   set frac = n - int
  260.   
  261.   if frac < 0 then
  262.     set frac = frac + 1
  263.     set int = int - 1
  264.   end if
  265.   
  266.   set fracSumIn = fracSumIn + frac
  267.   return int
  268. end storeFractionIn
  269.  
  270.  
  271.  
  272.  
  273. on playCut
  274.   global inChannel, ambience, ambiencePath, CDroot, cut
  275.   set selection = string( ambience( mGet, cut ))
  276.   sound playFile inChannel, CDroot & ambiencePath & selection
  277.   startCutTimer
  278. end playCut
  279.  
  280.  
  281.  
  282.  
  283. on startCutTimer
  284.   global cutStartTime
  285.   set cutStartTime = the timer
  286. end startCutTimer
  287.  
  288.  
  289.  
  290.  
  291. on playTime
  292.   global cutStartTime
  293.   return the timer - cutStartTime
  294. end playTime
  295.  
  296.  
  297.  
  298.  
  299. on stopAmbience
  300.   sound stop 1
  301.   sound stop 2
  302. end stopAmbience
  303.